<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<div
  class="block-tips aui-gutter-column-sm"
  *ngIf="
    rowCopy?.resource_sub_type === dataMap.Resource_Type.dbTwoTableSet.value
  "
>
  <i
    lv-icon="lv-icon-status-info"
    lvColorState="true"
    class="type-icon icon-tips"
  ></i>
  <span class="form-tips">
    {{ 'protection_db_two_tablespace_retsore_tips_label' | i18n }}
  </span>
</div>
<lv-form [formGroup]="formGroup" class="formGroup" lvKeepRequiredWidth>
  <lv-form-item *ngIf="!isDrill">
    <lv-form-label>
      {{ 'protection_restore_to_label' | i18n }}
    </lv-form-label>
    <lv-form-control>
      <lv-radio-group
        formControlName="restoreTo"
        [lvGroupName]="'restoreToGroup'"
      >
        <lv-group [lvGutter]="'20px'">
          <lv-radio
            [lvValue]="restoreLocationType.ORIGIN"
            [lvDisabled]="disableOriginLocation"
            [lv-tooltip]="
              disableOriginLocation
                ? ('protection_cloud_origin_restore_disabled_label' | i18n)
                : ''
            "
          >
            {{ 'common_restore_to_origin_location_label' | i18n }}
          </lv-radio>
          <lv-radio
            [lvValue]="restoreLocationType.NEW"
            [lvDisabled]="
              rowCopy?.resource_sub_type ===
              dataMap.Resource_Type.dbTwoTableSet.value
            "
          >
            {{ 'common_restore_to_new_location_label' | i18n }}
          </lv-radio>
        </lv-group>
      </lv-radio-group>
    </lv-form-control>
  </lv-form-item>
  <ng-container
    *ngIf="formGroup.value.restoreTo === restoreLocationType.ORIGIN"
  >
    <lv-form-item>
      <lv-form-label>
        {{ location }}
      </lv-form-label>
      <lv-form-control>
        <input type="text" formControlName="originalHost" lv-input />
      </lv-form-control>
    </lv-form-item>
  </ng-container>
  <ng-container *ngIf="formGroup.value.restoreTo === restoreLocationType.NEW">
    <aui-select-tag [formGroup]="formGroup" (updateTable)="updateTable($event)" [targetKey]="'host'" [isAgentTag]="true"></aui-select-tag>
    <lv-form-item>
      <lv-form-label lvRequired>
        {{ location }}
      </lv-form-label>
      <lv-form-control>
        <lv-select
          formControlName="host"
          [lvOptions]="options"
          lvValueKey="key"
          lvShowFilter
          lvFilterKey="label"
          lvFilterMode="contains"
          [lvDisabled]="
            formGroup.value.restoreTo === restoreLocationType.ORIGIN
          "
        >
        </lv-select>
      </lv-form-control>
    </lv-form-item>
    <lv-form-item>
      <lv-form-label lvRequired>
        {{ 'protection_target_instance_label' | i18n }}
      </lv-form-label>
      <lv-form-control>
        <lv-select
          formControlName="instance"
          [lvOptions]="instanceOptions"
          lvValueKey="key"
          lvShowFilter
          lvFilterKey="label"
          lvFilterMode="contains"
        >
        </lv-select>
      </lv-form-control>
    </lv-form-item>
    <lv-form-item>
      <lv-form-label lvRequired>
        {{ 'common_target_to_database_label' | i18n }}
      </lv-form-label>
      <lv-form-control>
        <lv-select
          formControlName="database"
          [lvOptions]="databaseOptions"
          lvValueKey="key"
          lvShowFilter
          lvFilterKey="label"
          lvFilterMode="contains"
        >
        </lv-select>
      </lv-form-control>
    </lv-form-item>
  </ng-container>
  <ng-container
    *ngIf="
      clusterType === dataMap.dbTwoType.dpf.value &&
      rowCopy?.backup_type === dataMap.CopyData_Backup_Type.log.value &&
      !!rowCopy?.restoreTimeStamp
    "
  >
    <lv-form-item>
      <lv-form-label>
        {{ 'explore_fail_on_pit_label' | i18n }}
        <i
          lv-icon="aui-icon-help"
          lvTooltipTheme="light"
          lv-tooltip="{{ 'explore_fail_on_pit_tips_label' | i18n }}"
          class="configform-constraint"
          lvColorState="true"
        >
        </i>
      </lv-form-label>
      <lv-form-control>
        <lv-switch formControlName="failOnPit"></lv-switch>
      </lv-form-control>
    </lv-form-item>
  </ng-container>
  <div class="advanced-container" *ngIf="!isDrill">
    <lv-collapse [lvType]="'simple'">
      <lv-collapse-panel [lvTitle]="titleTpl" [lvExpanded]="false">
        <lv-form-item>
          <lv-form-label>
            {{ 'protection_restore_pre_script_label' | i18n }}
            <i
              lv-icon="aui-icon-help"
              lvTooltipTheme="light"
              lv-tooltip="{{ 'common_script_oracle_linux_help_label' | i18n }}"
              class="configform-constraint"
              lvColorState="true"
            >
            </i>
          </lv-form-label>
          <lv-form-control [lvErrorTip]="scriptErrorTip">
            <input
              formControlName="preScript"
              lv-input
              placeholder="{{ 'common_script_linux_placeholder_label' | i18n }}"
            />
          </lv-form-control>
        </lv-form-item>
        <lv-form-item>
          <lv-form-label>
            {{ 'protection_restore_post_script_label' | i18n }}
            <i
              lv-icon="aui-icon-help"
              lvTooltipTheme="light"
              lv-tooltip="{{ 'common_script_oracle_linux_help_label' | i18n }}"
              class="configform-constraint"
              lvColorState="true"
            >
            </i>
          </lv-form-label>
          <lv-form-control [lvErrorTip]="scriptErrorTip">
            <input
              formControlName="postScript"
              lv-input
              placeholder="{{ 'common_script_linux_placeholder_label' | i18n }}"
            />
          </lv-form-control>
        </lv-form-item>
        <lv-form-item>
          <lv-form-label>
            {{ 'protection_restore_fail_script_label' | i18n }}
            <i
              lv-icon="aui-icon-help"
              lvTooltipTheme="light"
              lv-tooltip="{{ 'common_script_oracle_linux_help_label' | i18n }}"
              class="configform-constraint"
              lvColorState="true"
            >
            </i>
          </lv-form-label>
          <lv-form-control [lvErrorTip]="scriptErrorTip">
            <input
              formControlName="executeScript"
              lv-input
              placeholder="{{ 'common_script_linux_placeholder_label' | i18n }}"
            />
          </lv-form-control>
        </lv-form-item>
      </lv-collapse-panel>
    </lv-collapse>
  </div>
</lv-form>

<ng-template #titleTpl>
  <lv-group lvGutter="8px">
    <span class="custom-collapse-title-text">{{
      'common_advanced_label' | i18n
    }}</span>
    <i
      lv-icon="aui-icon-help"
      lvTooltipTheme="light"
      lv-tooltip="{{
        'protection_fileset_restore_advance_params_label' | i18n
      }}"
      lvColorState="true"
    >
    </i>
  </lv-group>
</ng-template>
